package com.woniuxy.main.handler;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.context.annotation.Scope;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.servlet.ModelAndView;

import com.woniuxy.main.service.ChatService;
import com.woniuxy.main.util.SessionUtil;

import lombok.Data;

@Data
@Controller
@RequestMapping("/chat")
@Scope("prototype")
public class ChatActionHandler {
	
	@Autowired
	private ChatService chatService;

	/**
	 * 当前用户向聊天对象发起
	 * 
	 * @param currentUid
	 * @param talkerUid
	 * @return
	 */
	@RequestMapping("/chatWindow")
	public ModelAndView ChatWindow(int currentUid,int talkerUid){
		currentUid = (int) SessionUtil.getSession().getAttribute("uid");
		ModelAndView modelAndView = new ModelAndView();
		
		//添加聊天对象用户id,name
		modelAndView.addObject("talkerUid", talkerUid);
		modelAndView.addObject("talkerCname", chatService.findNickName(talkerUid));
		
		//添加当前登录用户id,name
		modelAndView.addObject("currentUid", currentUid);
		modelAndView.addObject("currentSname", chatService.findNickName(currentUid));
		
		modelAndView.setViewName("/chat.html");
		return modelAndView;
	}
}
